//
// Created by wenyaxi on 24-10-28.
//
#include<common.h>
using namespace std;

class Solution {
public:
    int min_pre = 0;

    int pre_sum = 0;
    int ans = -INT_MAX;

    int maxSubArray(vector<int> &nums) {
        for (int i = 0; i < nums.size(); i++) {
            pre_sum += nums[i];
            ans = max(ans, pre_sum - min_pre);
            min_pre = min(min_pre, pre_sum);
        }
        return ans;
    }
};

int main() {
    //[-2,1,-3,4,-1,2,1,-5,4]
    auto solution = Solution();
    vector<int> nums{{-1}};
    int max_sub_array = solution.maxSubArray(nums);
    cout << max_sub_array << endl;
    return 0;
}
